package pers.cz.util;

import com.alibaba.fastjson.JSONArray;

import java.util.List;

/**
 * json格式化工具
 * @program: postgirl-collection-client
 * @description: JsonUtil
 * @author: Cheng Zhi
 * @create: 2022-03-03 14:23
 **/
public class JsonUtil {

    public static <T> List<T> jsonToList(String jsonString, Class<T> clazz) {

        if (clazz == null) {
           return jsonToList(jsonString);
        }
        @SuppressWarnings("unchecked")
        List<T> ts = (List<T>) JSONArray.parseArray(jsonString, clazz);
        return ts;
    }

    public static <T> List<T> jsonToList(String jsonString) {
        @SuppressWarnings("unchecked")
        List<T> ts = (List<T>) JSONArray.parseArray(jsonString);
        return ts;
    }
}
